<template>
  <div :class="size">
    <div class="upload-container">
      <div class="image-uploader" @click="drawer = true">
        <!-- <i v-if="!tempUrl" class="el-icon-plus avatar-uploader-icon" /> -->
        <img class="tempimg" v-if="!tempUrl"   src='@/assets/images/addimg.png' />
        <vimage class="tempimg" v-else :src="tempUrl" ></vimage>
        <i v-if="tempUrl" class="font icon-abl-close el-icon-error" @click.stop="clearList"></i>
      </div>
    </div>
    <el-dialog class="selectimg" title="图片选择器" :visible.sync="drawer" destroy-on-close width="1000px" append-to-body @open='openimg'>
      <SelectImg :rk='rk' :limit="imglimit" @closepup='closepup' :data="imgdata" @changeImg="changeImg"></SelectImg>
    </el-dialog>
  </div>
</template>

<script>
import SelectImg from '@/components/SelectImg/index';
export default {
  name: 'SingleImageUpload',
  props: {
    tempUrl: {
      type: String,
      default: ''
    },
    size: {
      type: String,
      default: 'upload-container'
    }
  },
  data() {
    return {
      drawer: false,
      imgdata: [],
      imglimit: 1,
      url: process.env.VUE_APP_BASE_API,
      rk:1,
      // tempUrl: '',
    };
  },
  computed: {
    imageUrl() {
      return this.value;
    }
  },
  components: {
    SelectImg
  },
  mounted() {

  },
  methods: {
    rmImage() {
      this.emitInput('');
    },
    changeImg(data) {
      this.drawer = false;
      let val = data[0].pic_path;
      this.$emit('input', val);
    },
    openimg(){
      this.rk++
    },
    closepup(){
      this.drawer=false
    },
    clearList(){
      this.$emit('input', '');
    }
  }
};
</script>

<style lang="scss" scoped>
@import '~@/styles/mixin.scss';
.upload-container {
  width: 100%;
  height: 100%;
  position: relative;
  @include clearfix;
  // border: 1px solid #f5f2f0;
  .image-uploader {
    width: 100%;
    height: 100%;
    float: left;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
.tempimg {
  width: 100%;
  height: 100%;
}

.upload-container_big {
  width: 100%;

  .tempimg {
    width: 300px;
    height: 150px;
  }
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
}
.font{
  font-weight: bold;
  position: absolute;
  right: 0;
  top: 0;
  line-height: 16px;
  text-align: center;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  transform: translate(40%,-30%);
  cursor: pointer;
  font-size: 16px;
  border-radius: 50%;
  box-sizing: border-box;
}
</style>
